<template>
  <div class="app-container" v-loading="pageLoading">
    <el-button type="primary" class="fr" @click="createItem" v-permission="'ppmatch.add'">创建</el-button>
    <div class="filter-container">
      <el-input style="width: 300px;" placeholder="输入查询关键字按回车" clearable prefix-icon="el-icon-search"
        class="filter-item" @keyup.enter.native="research" @clear="research" v-model="query.queryString"></el-input>
    </div>
    <z-table :list="list" :tableProps="tableProps" :columns="columns" @editItem="editItem" @deleteItem="deleteItem">
    </z-table>
    <z-pagination :pagination="pagination" :total="total" :page.sync="query.page" :limit.sync="query.size"
      @change="getList"></z-pagination>
    <z-form-dialog :name="name" :data="data" :formProps="formProps" :fields="fields" @submit="submit"
      :submitLoading="submitLoading" :visible.sync="editFormVisible"></z-form-dialog>
  </div>
</template>

<script>
import commonMixin from '@/views/_common/mixin'

const emptyData = {}
export default {
  mixins: [commonMixin],
  name: 'ppmatch',
  data: function () {
    return {
      name: '工序人员对应',
      api: this.$api.ppmatch,
      pageLoading: false,
      submitLoading: false,
      // query: {
      //   page: 1,
      //   size: 10,
      // },
      list: [],
      // total: 0,
      data: { ...emptyData },
      editFormVisible: false,
      columns: [
        { title: '工序', key: 'group_name', width: 120 },
        { title: '工段', key: 'section_name', width: 120 },
        { title: '人员', key: 'user_id', width: 100 },
        { title: '人员姓名', key: 'username', width: 120 },
        { title: '备注', key: 'remarks' },
        { title: '修改人', key: 'modify_user', width: 100 },
        { title: '最后修改', key: 'modify_time', width: 140 },
      ],
      fields: [
        {
          title: '工序',
          key: 'group_id',
          name: 'select',
          options: [],
          props: {},
        },
        {
          title: '人员',
          key: 'user_id',
          name: 'select',
          options: [],
          props: {},
        },
        {
          title: '备注',
          key: 'remarks',
        },
      ],
    }
  },
  methods: {
    submit: function () {
      this.submitLoading = true
      let url = this.$api.ppmatch + 'add'
      this.$request(url, this.data, 'post')
        .then((r) => {
          this.submitLoading = false
          this.$message({ message: '操作成功', type: 'success' })
          this.editFormVisible = false
          this.getList()
        })
        .catch(() => {
          this.submitLoading = false
        })
    },
  },
  created: function () {
    this.getList()
    this.$request(this.$api.group + 'getlist')
      .then((r) => {
        this.setFieldOptions('group_id', r, r[0].id == undefined ? 'group_code' : 'id', 'group_name')
      })
      .catch(() => {})
    this.$request(this.$api.user + 'getlist')
      .then((r) => {
        console.info(r)
        this.setFieldOptions('user_id', r.list, 'userid', ['userid', 'username'])
      })
      .catch(() => {})
  },
  watch: {},
}
</script>

<style scoped>
</style>
